﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Business;
using Business.DataBusiness;

namespace MuaBanDT
{
    public partial class ChiTietHoaDonNhap : Form
    {
        Utilities getData = new Utilities();
        public ChiTietHoaDonNhap()
        {
            InitializeComponent();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                ChiTietHDN a = new ChiTietHDN();
                a.MaCTHDN = getData.CreateID("ChiTietHDN", "CTN");
                a.MaHDN = this.txMaHDN.Text;
                a.MaDT = this.txtMaDT.Text;
                a.DonViTinh = this.txtDonViTinh.Text;
                a.SoLuong = int.Parse(this.txtSoLuong.Text);
                a.DonGia = float.Parse(this.txtDonGia.Text);
                txtMaCTHDN.Text = a.MaCTHDN;
                if (a.Insert() == 1)
                {
                    MessageBox.Show("Lưu thành công", "Nhập Hàng");
                    

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
            
           
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            Xoa();
        }
        private void Xoa()
        {
            this.txtMaCTHDN.Text= "";
            this.txMaHDN.Text = "";
            this.txtMaDT.Text = "";
            this.txtDonViTinh.Text = "";
            this.txtSoLuong.Text = "";
            this.txtDonGia.Text = "";
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ChiTietHoaDonNhap_Load(object sender, EventArgs e)
        {
            this.txMaHDN.Items.AddRange(getData.GetHoaDon("HoaDonNhap"));
        }

        private void txtSoLuong_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                MessageBox.Show("Bạn chỉ được nhập số", "Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                e.Handled = true;
            }
        }

        private void txtDonGia_KeyPress(object sender, KeyPressEventArgs e)
        {
            txtSoLuong_KeyPress(sender, e);
        }       
    }
}
